# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.


import datetime


def find_or_create_for_emp_month( cls, self, values ):
        employee_id = values.get('employee_id')
        date_month = values.get('date_month')
        date_month = datetime.datetime.strptime(date_month,'%Y-%m-%d')
        date_month = datetime.datetime.strftime(date_month, "%Y-%m") + '-01'

        domain =[( 'employee_id','=', employee_id),
            ('date_month','=',date_month)
        ]

        res = self.search(domain,limit=1)
        if res:
            return res

        values['date_month'] = date_month
        return super(cls, self).create(values)

def write_for_emp_month( cls, self, values ):
        if values.get('employee_id'):
            del values['employee_id']

        if values.get('date_month'):
            del values['date_month']

        return super(cls, self).write(values)
